package Messages;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import ocsf.server.ConnectionToClient;
import server.SQLConnection;
/**
 * This class implements show supplier from data in DB 
 * @author Gabi Revah
 * @author Aviad Almog
 */ 
public class MessageShowSuppliers {

	private ConnectionToClient client ;
	private String[] str; 

/**
 * Constructor of this class 
 * @param str
 * @param client
 */
public MessageShowSuppliers(String[] str, ConnectionToClient client) {
	
	this.client= client ;
	this.str= str; 
}
/**
 * This method is showing supplier details 
 * @throws SQLException
 * @throws IOException
 */
public void ShowSupp() throws SQLException, IOException{
	
	SQLConnection sc = new SQLConnection();
	
	java.sql.PreparedStatement ps = sc.getConnection().prepareStatement("SELECT * FROM db.suppliers");
	ResultSet SuppRes= ps.executeQuery();
	ArrayList<Object> supp=new ArrayList<Object>();
	supp.add("ShowSupp");
	while (SuppRes.next())
	{
		supp.add(SuppRes.getInt(1));
		supp.add(SuppRes.getString(2));
		supp.add(SuppRes.getString(3));
		supp.add(SuppRes.getString(4));
		supp.add(SuppRes.getString(5));
		supp.add(SuppRes.getString(6));
	}
	client.sendToClient(supp);
}
}
